package cn.cloudtogo.adaptation.amqp;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;

/**
 * @author yaolianhua789@gmail.com
 **/
@ConfigurationProperties("gendb.rabbitmq")
@Data
@Slf4j
public class ExternalRabbitmqProperties {

    public static final String LISTENER_ENABLED = "gendb.rabbitmq.listener.enabled";
    private Listener listener = new Listener();

    private String host;
    private Integer port;

    private String username;
    private String password;

    @PostConstruct
    public void print() {
        log.info("[load external rabbitmq. url {} ]", String.format("amqp://%s@%s:%s", username, host, port));
        if (!this.listener.isEnabled()) {
            log.warn("[Event listener is not turned on, all events will be ignored]");
        }
    }

    @Data
    public static class Listener {
        private boolean enabled;
    }
}
